home *** CD-ROM | disk | FTP | other *** search
/ Giga Games 1 / Giga Games.iso / net / usenet / volume1 / rot < prev    next >
Encoding:
Text File  |  1987-04-17  |  10.5 KB  |  467 lines

  1. Path: seismo!rutgers!mit-eddie!uw-beaver!tektronix!tekgen!tekred!games-request
  2. From: games-request@tekred.TEK.COM
  3. Newsgroups: mod.sources.games
  4. Subject: v01i002:  rot - waterfall terminal display
  5. Message-ID: <1095@tekred.TEK.COM>
  6. Date: 17 Apr 87 21:25:24 GMT
  7. Sender: billr@tekred.TEK.COM
  8. Lines: 456
  9. Approved: billr@tekred.TEK.COM
  10.  
  11. Submitted by: seismo!ut-sally!shell!neuro1!hyd-ptd!peter
  12. Mod.sources.games: Volume 1, Issue 2
  13. Archive-name: rot
  14.  
  15.     [This was originally posted to net.bizarre back in July 1985.
  16.      I have compiled and run this sucessfully on our 4.3bsd Vax
  17.      and don't see any particular machine/os dependencies, other
  18.      than requiring term{lib|cap}. -br ]
  19.  
  20. #! /bin/sh
  21. # This is a shell archive.  Remove anything before this line, then unpack
  22. # it by saving it into a file and typing "sh file".  To overwrite existing
  23. # files, type "sh file -c".  You can also feed this as standard input via
  24. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  25. # will see the following message at the end:
  26. #        "End of shell archive."
  27. # Contents:  README Makefile rot.c
  28. # Wrapped by billr@tekred on Fri Apr 17 14:20:46 1987
  29. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  30. if test -f README -a "${1}" != "-c" ; then 
  31.   echo shar: Will not over-write existing file \"README\"
  32. else
  33. echo shar: Extracting \"README\" \(455 characters\)
  34. sed "s/^X//" >README <<'END_OF_README'
  35. XThis program cascades letters from the top of the terminal screen
  36. Xto the bottom in a waterfall effect.  There was a note in the
  37. Xoriginal posting about this program not working on terminals that
  38. Xrequire padding (PC is read but not used).  Also, this will be
  39. Xpretty slow at lower baudrates.
  40. X
  41. X--
  42. XOriginal source from:
  43. X
  44. X    Peter da Silva (ihnp4!shell!neuro1!{hyd-ptd,datafact,baylor}!peter)
  45. X
  46. XMakefile and README from:
  47. X
  48. X    Bill Randle (billr@tekred.TEK.COM)
  49. END_OF_README
  50. if test 455 -ne `wc -c <README`; then
  51.     echo shar: \"README\" unpacked with wrong size!
  52. fi
  53. # end of overwriting check
  54. fi
  55. if test -f Makefile -a "${1}" != "-c" ; then 
  56.   echo shar: Will not over-write existing file \"Makefile\"
  57. else
  58. echo shar: Extracting \"Makefile\" \(99 characters\)
  59. sed "s/^X//" >Makefile <<'END_OF_Makefile'
  60. X# Simple makefile for rot program
  61. X
  62. Xrot:    rot.c
  63. X    cc -O -o rot rot.c -ltermlib
  64. X
  65. Xtest:    rot
  66. X    rot <rot.c
  67. END_OF_Makefile
  68. if test 99 -ne `wc -c <Makefile`; then
  69.     echo shar: \"Makefile\" unpacked with wrong size!
  70. fi
  71. # end of overwriting check
  72. fi
  73. if test -f rot.c -a "${1}" != "-c" ; then 
  74.   echo shar: Will not over-write existing file \"rot.c\"
  75. else
  76. echo shar: Extracting \"rot.c\" \(7528 characters\)
  77. sed "s/^X//" >rot.c <<'END_OF_rot.c'
  78. X#include <stdio.h>
  79. X
  80. X/*        -- Miscellaneous defines --                     */
  81. X#define FALSE 0
  82. X#define TRUE 1
  83. X#define MAXCOL 80
  84. X#define MAXLI 24
  85. X
  86. Xextern char *tgetstr();
  87. X
  88. Xint lastx, lasty;
  89. Xstruct _c {
  90. X    struct _c *c_next;
  91. X    int c_line, c_column;
  92. X    char c_mark;
  93. X} *clist;
  94. X
  95. X/*        -- Global variables --                         */
  96. Xchar *tent;                                               /* Pointer to tbuf */
  97. Xchar *PC;                                                    /* Pad character */
  98. Xchar *UP, *BC;                                /* Upline, backsapce character */
  99. Xshort ospeed;                                       /* Terminal output speed */
  100. Xint tglen;
  101. X
  102. Xchar *cm,                                                   /* Cursor motion */
  103. X     *cl,                                                    /* Clear screen */
  104. X     *ti,                            /* Init terminal */
  105. X     *te;                           /* Reset terminal */
  106. Xint  li,                                                  /* lines on screen */
  107. X     co;                                                    /* columns ditto */
  108. Xchar screen[MAXLI+1][MAXCOL];
  109. Xchar newscreen[MAXLI+1][MAXCOL];
  110. X
  111. Xmain(ac, av)
  112. Xint ac;
  113. Xchar **av;
  114. X{
  115. X    srand(getpid());
  116. X    tinit(getenv("TERM"));
  117. X    if(av[1])
  118. X        while(*++av)
  119. X            dropf(*av);
  120. X    else
  121. X        fdropf(stdin);
  122. X    tend();
  123. X}
  124. X
  125. Xat(x, y, c)
  126. Xint x, y;
  127. Xchar c;
  128. X{
  129. X#ifdef DEBUG
  130. X    _at(x, y);
  131. X#else
  132. X    if(y==lasty) {
  133. X        if(x!=lastx) {
  134. X            if(x<lastx && lastx-x<tglen)
  135. X                while(x<lastx) {
  136. X                    putchar('\b');
  137. X                    lastx--;
  138. X                }
  139. X            else if(x>lastx && x-lastx<tglen)
  140. X                while(x>lastx) {
  141. X                    putchar(newscreen[lasty][lastx]);
  142. X                    lastx++;
  143. X                }
  144. X            else
  145. X                _at(x, y);
  146. X        }
  147. X    } else
  148. X        _at(x, y);
  149. X#endif
  150. X    c &= ~0200;
  151. X    putchar(c);
  152. X    if(c >= ' ' && c != '\177')
  153. X        lastx++;
  154. X    if(lastx>=co) {
  155. X        lastx -= co;
  156. X        lasty++;
  157. X    }
  158. X}
  159. X
  160. X_at(x, y)
  161. Xint x, y;
  162. X{
  163. X    outs(tgoto(cm, x, y));
  164. X    lastx = x;
  165. X    lasty = y;
  166. X}
  167. X
  168. Xtinit(name)
  169. Xchar *name;
  170. X{
  171. X    static char junkbuf[1024], *junkptr;
  172. X    char tbuf[1024];
  173. X    int  intr();
  174. X
  175. X    junkptr = junkbuf;
  176. X
  177. X    tgetent(tbuf, name);
  178. X
  179. X    PC = tgetstr("pc", &junkptr);
  180. X    UP = tgetstr("up", &junkptr);
  181. X    BC = tgetstr("bc", &junkptr);
  182. X    cm = tgetstr("cm", &junkptr);
  183. X    cl = tgetstr("cl", &junkptr);
  184. X    ti = tgetstr("ti", &junkptr);
  185. X    te = tgetstr("te", &junkptr);
  186. X    li = min(tgetnum("li"), MAXLI);
  187. X    co = min(tgetnum("co"), MAXCOL);
  188. X    tglen = strlen(tgoto(co-1, li-1));
  189. X}
  190. X
  191. Xtend()
  192. X{
  193. X    outs(te);
  194. X    _at(0, li-1);
  195. X    putchar('\n');
  196. X    fflush(stdout);
  197. X}
  198. X
  199. Xreadscreen(fp)
  200. XFILE *fp;
  201. X{
  202. X    int line, column, p;
  203. X    char tmp[256];
  204. X
  205. X    for(line=0; line<li; line++)
  206. X        for(column=0; column<co; column++)
  207. X            newscreen[line][column] = screen[line][column] = ' ';
  208. X    for(column=0; column<co; column++)
  209. X        newscreen[li][column] = screen[li][column] = '*';
  210. X    line=0;
  211. X    while(line<li) {
  212. X        if(!fgets(tmp, 256, fp))
  213. X            return;
  214. X
  215. X        for(column=0, p=0; tmp[p]; p++) {
  216. X            tmp[p] &= ~0200;
  217. X            if(tmp[p] < ' ' || tmp[p] == 127)
  218. X                switch(tmp[p]) {
  219. X                    case '\t':
  220. X                        while(++column % 8)
  221. X                            continue;
  222. X                        break;
  223. X                    case '\n':
  224. X                        column = 0;
  225. X                        line++;
  226. X                        break;
  227. X                    default:
  228. X                        newscreen[line][column] = '^';
  229. X                        column++;
  230. X                        if(column>=co) {
  231. X                            column -= co;
  232. X                            line++;
  233. X                        }
  234. X                        newscreen[line][column] =
  235. X                            (tmp[p]+'@') & 127;
  236. X                        column++;
  237. X                        break;
  238. X                }
  239. X            else {
  240. X                newscreen[line][column] = tmp[p];
  241. X                column++;
  242. X            }
  243. X            if(column >= co) {
  244. X                column -= co;
  245. X                line++;
  246. X            }
  247. X            if(line >= li)
  248. X                break;
  249. X        }
  250. X    }
  251. X    for(column=0; column<co; column++)
  252. X        newscreen[line][column] = screen[li][column] = '*';
  253. X}
  254. X
  255. Xdrawscreen()
  256. X{
  257. X    lastx = lasty = 0;
  258. X    outs(cl);
  259. X    update();
  260. X}
  261. X
  262. Xupdate() /* copy new screen back to old screen */
  263. X{
  264. X    int l, c;
  265. X
  266. X    for(l=0; l<li; l++)
  267. X        for(c=0; c<co; c++)
  268. X            if(screen[l][c] != newscreen[l][c]) {
  269. X                if((screen[l][c] & ~0200) !=
  270. X                   (newscreen[l][c] & ~0200))
  271. X                    at(c, l, newscreen[l][c]);
  272. X                screen[l][c] = newscreen[l][c];
  273. X            }
  274. X}
  275. X
  276. Xdrop(line, column)
  277. Xint line, column;
  278. X{
  279. X    struct _c *hold;
  280. X
  281. X    if(line<0 || line>=li || column<0 || column>=co ||
  282. X       (line>=li-2 && column >= co-1) || /* scroll potential */
  283. X       screen[line][column]==' ' || /* empty */
  284. X       screen[line][column] & 0200) /* already in list */
  285. X        return;
  286. X    if(screen[line+1][column]!=' ' &&
  287. X       (column==co-1 ||screen[line+1][column+1]!=' ') &&
  288. X       (column==0 ||screen[line+1][column-1]!=' '))
  289. X        return;
  290. X
  291. X    hold = (struct _c *) malloc(sizeof(struct _c));
  292. X    hold -> c_next = clist;
  293. X    hold -> c_column = column;
  294. X    hold -> c_line = line;
  295. X    hold -> c_mark = 0;
  296. X    screen[line][column] |= 0200;
  297. X    clist = hold;
  298. X}
  299. X
  300. Xdrops()
  301. X{
  302. X    int l, c;
  303. X    struct _c *hold;
  304. X    for(hold = clist; hold; hold=hold->c_next) {
  305. X        int line = hold->c_line, column=hold->c_column;
  306. X        if(line>= li-2 && column>=co-1) {
  307. X            newscreen[line][column] &= ~0200;
  308. X            screen[line][column] &= ~0200;
  309. X            hold->c_mark = 1;
  310. X            continue;
  311. X        }
  312. X        drop(line+1, column);
  313. X        drop(line, column+1);
  314. X        drop(line-1, column);
  315. X        drop(line, column-1);
  316. X        if(newscreen[line+1][column]==' ') {
  317. X            newscreen[line+1][column] = screen[line][column];
  318. X            newscreen[line][column] = ' ';
  319. X            line++;
  320. X        } else if(rand()&01000) {
  321. X            if(column>0 && newscreen[line][column-1] == ' ' &&
  322. X                newscreen[line+1][column-1]==' ') {
  323. X                newscreen[line][column-1] =
  324. X                    screen[line][column];
  325. X                newscreen[line][column] = ' ';
  326. X                column--;
  327. X            }
  328. X            else if(column<co-1 &&
  329. X                newscreen[line][column+1] == ' ' &&
  330. X                newscreen[line+1][column+1]==' ') {
  331. X                    newscreen[line][column+1] =
  332. X                        screen[line][column];
  333. X                    newscreen[line][column] = ' ';
  334. X                    column++;
  335. X            }
  336. X            else {
  337. X                screen[line][column] &= ~0200;
  338. X                newscreen[line][column] &= ~0200;
  339. X                hold -> c_mark = 1;
  340. X            }
  341. X        } else {
  342. X            if(column<co-1 && newscreen[line][column+1] == ' ' &&
  343. X                newscreen[line+1][column+1]==' ') {
  344. X                newscreen[line][column+1] =
  345. X                    screen[line][column];
  346. X                newscreen[line][column] = ' ';
  347. X                column++;
  348. X            }
  349. X            else if(column>0 && newscreen[line][column-1] == ' ' &&
  350. X                newscreen[line+1][column-1]==' ') {
  351. X                newscreen[line][column-1] =
  352. X                    screen[line][column];
  353. X                newscreen[line][column] = ' ';
  354. X                column--;
  355. X            }
  356. X            else {
  357. X                newscreen[line][column] &= ~0200;
  358. X                screen[line][column] &= ~0200;
  359. X                hold -> c_mark = 1;
  360. X            }
  361. X        }
  362. X        hold -> c_column = column;
  363. X        hold -> c_line = line;
  364. X        fflush(stdout);
  365. X    }
  366. X
  367. X    while(clist && clist->c_mark) {
  368. X        struct _c *p = clist;
  369. X        clist = clist -> c_next;
  370. X        free(p);
  371. X    }
  372. X    hold = clist;
  373. X    while(hold && hold->c_next)
  374. X        if(hold->c_next->c_mark) {
  375. X            struct _c *p = hold->c_next;
  376. X            hold->c_next = p->c_next;
  377. X            free(p);
  378. X        } else
  379. X            hold=hold->c_next;
  380. X}
  381. X
  382. Xdroplet(line, column)
  383. Xint line, column;
  384. X{
  385. X    int ret;
  386. X    while(column>=0 && screen[line][column]!=' ')
  387. X        column--;
  388. X    column++;
  389. X    while(column<co && screen[line][column]!=' ')
  390. X        drop(line, column++);
  391. X    ret = clist != 0;
  392. X    while(clist) {
  393. X        drops();
  394. X        update();
  395. X    }
  396. X    return ret;
  397. X}
  398. X
  399. Xdropscreen()
  400. X{
  401. X    int column, line;
  402. X    int rubbish = 0, count = 0;
  403. X
  404. X    do {
  405. X        int start, limit, incr;
  406. X        count++;
  407. X        rubbish = 0;
  408. X        if(count&1) { start=li-2; limit=0; incr = -1; }
  409. X        else { start=0; limit=li-2; incr=1; }
  410. X        for(line=start; line!=limit && !rubbish; line+=incr) {
  411. X            if(line&1)
  412. X                for(column=0; column<co && !rubbish; column++)
  413. X                    rubbish += droplet(line, column);
  414. X            else
  415. X                for(column=co-1; column>=0 && !rubbish; column--)
  416. X                    rubbish += droplet(line, column);
  417. X        }
  418. X    } while(rubbish);
  419. X}
  420. X
  421. Xdropf(file)
  422. Xchar *file;
  423. X{
  424. X    FILE *fp;
  425. X
  426. X    if(!(fp = fopen(file, "r"))) {
  427. X        perror(file);
  428. X        return -1;
  429. X    }
  430. X    fdropf(fp);
  431. X}
  432. X
  433. Xfdropf(fp)
  434. XFILE *fp;
  435. X{
  436. X    int i;
  437. X
  438. X    while(!feof(fp)) {
  439. X        readscreen(fp);
  440. X        drawscreen();
  441. X        for(i=0; i<20; i++)
  442. X            droplet((rand()>>4) % li, (rand()>>4) % co);
  443. X        dropscreen();
  444. X    }
  445. X}
  446. X
  447. Xouts(s)
  448. Xchar *s;
  449. X{
  450. X    fputs(s, stdout);
  451. X}
  452. X
  453. Xmin(a, b)
  454. Xint a, b;
  455. X{
  456. X    if(a<b) return a;
  457. X    return b;
  458. X}
  459. END_OF_rot.c
  460. if test 7528 -ne `wc -c <rot.c`; then
  461.     echo shar: \"rot.c\" unpacked with wrong size!
  462. fi
  463. # end of overwriting check
  464. fi
  465. echo shar: End of shell archive.
  466. exit 0
  467.